{extend name="admin@index_layout"/}
{block name="main"}
<table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
<script type="text/html" id="barTool">
    <a data-href='{{d.name}}' data-href2='{{d.id}}' class="layui-btn layui-btn-danger layui-btn-xs btn-chooseone"><i class="iconfont icon-right"></i> 选择</a>
</script>

<script type="text/html" id="picTpl">

    <img style="max-width:80px; max-height:30px;" src="{{d.img}}" data-image="{{d.name}}">

</script>
{/block}
{block name="script"}
<script>
    layui.use(['yznTable','yzn','table','yznForm','yznUpload'], function() {
        var yznTable = layui.yznTable,
            yzn = layui.yzn,
            yznForm = layui.yznForm,
            yznUpload = layui.yznUpload,
            table =layui.table;
        var urlArr = [];

        var init = {};

        yznTable.render({
            init: init,
            id: 'dataTable',
            toolbar: ['refresh'],
            elem: '#dataTable',
            url: '{:url("pzIndex")}?order_id={$order_id}',
            cols: [
                [
                    //关联会员 陪诊等级
                    // {type: 'checkbox', fixed: 'left'},
                    {field: 'id', width: '4%', title: 'ID'},
                    {field: 'nickname', align: "center", width: '15%', title: '关联会员',search: false},
                    {field: 'name', align: "center", width: '20%', title: '姓名',searchOp: 'like'},
                    {field: 'img', align: "center", width: '10%', title: '头像', templet: '#picTpl', search: false},
                    {field: 'phone', align: "center", width: '30%', title: '电话',search: false},
                    {field: 'pz_level_name', align: "center", width: '20%', title: '陪诊等级',search: false},

                    // {field: 'pz_volume', align: "center", width: '10%', title: '总营业额',search: false},
                    // {field: 'order_num', align: "center", width: '10%', title: '服务次数',search: false},

                    // {field: 'status_time', align: "center", width: '15%', title: '创建时间',search: false},
                    {fixed: 'right', align: "center", width: '20%', title: '操作', toolbar: '#barTool'}//delete'
                ]
            ],
            page: {},
            done: function(res, curr, count){
                yznUpload.api.upload('.faupload', function () {
                    $("[data-table-refresh]").trigger("click");
                });
            }
        });

        yznTable.bindevent();

        table.on('checkbox(dataTable_LayFilter)', function(obj){
            urlArr = [];
            var checkStatus = table.checkStatus('dataTable').data;
            for (var i = 0; i < checkStatus.length; i++) {
                urlArr.push(checkStatus[i]['name']);
            }
        });

        //选择单个
        $(document).on('click', '.btn-chooseone', function() {
            var that = $(this),
                index = that.parents('tr').eq(0).data('index'),
                tr = $('.layui-table-body').find('tr[data-index="' + index + '"]'),
                href = !that.attr('data-href') ? that.attr('href') : that.attr('data-href'),
                href2 = !that.attr('data-href2') ? that.attr('href2') : that.attr('data-href2');
                order_id={$order_id};
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('dispatch2')}",//提交URL
                data: {'pz_id': href2,'order_id':order_id},//提交的数据
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg('分配完成');
                        setTimeout(function() {
                             // window.parent.location.reload();
                            yzn.close({ url: href, multiple: false});
                        }, 1000);
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });

        });

        // 选中多个 todo翻页失效
        $(document).on("click", ".btn-choose-multi", function () {
            yzn.close({ url: urlArr.join(","), multiple: false});
        });
    });
</script>
{/block}